package oo

import (
	"elegantGo/chapter17/controller/response"
	"elegantGo/chapter17/oo/primitive"
	"elegantGo/chapter17/oo/vip"
)

type Vips []Vip

type Vip interface {
	GetID() int
	SetID(id int)
	GetCategory() int
	SetCategory(v int)
	GetName() string
	SetName(v string)
	GetPrice() int
	SetPrice(v int)
	GetDuration() int
	SetDuration(v int)

	Mapper() *response.Vip
}

func NewVip() Vip {
	var trait Vip = new(baseVip)
	return trait
}

func (oo Vips) Mapper() response.Vips {
	size := len(oo)
	respArticles := make(response.Vips, size)
	for i := 0; i < size; i++ {
		respArticles[i] = oo[i].Mapper()
	}
	return respArticles
}

type baseVip struct {
	id       primitive.ID
	category vip.Category
	name     vip.Name
	price    primitive.Fen
	duration vip.Duration
}

func (oo *baseVip) GetID() int {
	return oo.id.Value()
}

func (oo *baseVip) SetID(v int) {
	oo.id.SetValue(v)
}

func (oo *baseVip) GetCategory() int {
	return oo.category.Value()
}

func (oo *baseVip) SetCategory(v int) {
	oo.category.SetValue(v)
}

func (oo *baseVip) GetName() string {
	return oo.name.Value()
}

func (oo *baseVip) SetName(v string) {
	oo.name.SetValue(v)
}

func (oo *baseVip) GetPrice() int {
	return oo.price.Value()
}

func (oo *baseVip) SetPrice(v int) {
	oo.price.SetValue(v)
}

func (oo *baseVip) GetDuration() int {
	return oo.duration.Value()
}

func (oo *baseVip) SetDuration(v int) {
	oo.duration.SetValue(v)
}

func (oo *baseVip) Mapper() *response.Vip {
	if oo == nil {
		return nil
	}
	respUser := new(response.Vip)
	respUser.ID = oo.id.Value()
	respUser.Category = oo.category.Value()
	respUser.Name = oo.name.Value()
	respUser.Price = oo.price.ToYuan()
	respUser.Duration = oo.duration.Value()

	return respUser
}
